package com.yiming.shiro.controller;

import com.yiming.shiro.controller.vo.CommonResponse;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class AuthorizationExceptionHandler {

    @ResponseBody
    @ExceptionHandler(value = AuthorizationException.class)
    public CommonResponse handle(AuthorizationException e) {
        return CommonResponse.builder()
                .code(AuthorizationCode.NO_PERMISSION.name())
                .message(e.getMessage())
                .build();
    }

    private enum AuthorizationCode {
        NO_PERMISSION
    }
}
